package com.java1412.mq;

import com.java1412.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author java1412
 * @create 2021-07-07 14:35
 */
@Slf4j
@Component
public class RabbitProducer {
    @Autowired
    private AmqpTemplate template;

    public void sendMsg() {
        // Message msg = new Message();
        // template.send(msg);
        // 第一个参数是路由键
        String content = "hello," + new Date();
        System.out.println("消息发送---->content=" + content);
        template.convertAndSend("firstRabbit", content);
    }

    // 发送对象
    public void sendUser() {
        User user = new User();
        user.setId(1L);
        user.setUsername("java1412");
        user.setPassword("123");
        System.out.println("消息发送--->User=" + user.toString());
        template.convertAndSend("firstObject", user);
    }
}
